<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>评价</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <style>
        body {
            background: #f3f3f3;
            font-size: 14px;
        }

        .aui-icon-left {
            padding-left: 10px;
        }

        .aui-slide-page-active {
            background: #327afa;
        }

        header {
            width: 100%;
            height: 45px;
            background: #fff;
            position: fixed !important;
            z-index: 9;
            margin-bottom: 15px;
            top: 0;
        }

        .win_title {
            text-align: center;
            width: 100%;
            line-height: 45px;
            height: 45px;
            font-size: 16px;
        }

        .aui-iconfont {
            position: absolute;
        }

        .aui-list-view:after {
            border: none;
        }

        .aui-pull-right {
            margin-right: 20px;
        }

        .cancel {
            background: #d7e5ff;
            border-color: #d7e5ff;
            color: #327afa;
            width: 50%;
            float: left;
        }

        .confirm {
            width: 50%;
            float: left;
        }

        input[type="password"] {
            line-height: 25px;
            margin: 0;
            width: inherit;
            padding: 0;
            border: 0;
        }

        .myBtn {
            position: fixed;
            bottom: 0;
        }


        .evaluateInfo {
            padding: 15PX;
            background: #FFF;
        }

        .proInfo img {
            float: left;
            width: 60px;
            min-width: 60px;
            margin-right: 8px;
        }

        .good-price {
            margin-top: 3px;
        }

        .evualuateLilst li {
            margin-top: 5px;
            overflow: hidden;
        }

        .aui-icon-favorfill {
            position: relative;
            color: #d9d9d9;
            font-size: 18px;
        }

        .aui-icon-favorfill.active {
            color: #ff3333 !important;
        }

        textarea {
            margin: 0;
            height: 100px;
            overflow-y: auto;
        }

        .sumRed {
            color: red;
            font-weight: bold;
        }

        .evaluteValue {
            display: block;
            border: 1px solid #d9d9d9;
            float: left;
            padding: 5px 12px;
            border-radius: 5px;
            margin-right: 10px;
            margin-top: 5px;
            position: relative;
        }

        .evaluteValue.active {
            border-color: #327afa;
        }

        .evaluteValue.active:before {
            content: "";
            position: absolute;
            width: 0;
            height: 0;
            border-right: 22px solid #327afa;
            border-top: 15px solid transparent;
            bottom: 0;
            right: 0;
        }

        .evaluteValue.active:after {
            content: "\e645";
            position: absolute;
            bottom: -6px;
            right: 0;
            color: #fff;
            font-family: "auiicon" !important;
        }

        .waring, .manyiWaring, .fuwuWaring, .suduWaring {
            visibility: hidden;
            font-size: 12px;
        }

        .waring:not(:first-of-type) {
            width: 100%;
            float: left;
            margin-top: 5px;
        }

        .compare {
            background: #fff;
            margin-top: 15px;
            padding: 15px;
        }

        .manyi {
            margin: 5px 0;
        }

        .contain {
            /*display: none;*/
        }
    </style>
</head>
<body>
<div class="contain" id="orderInfo-content">
    <!--<ul class="aui-list-view">-->
    <!--<li class="aui-list-view-cell">-->
    <!--<div>订单号：<span class="orderNo"></span></div>-->
    <!--<div>下单时间：<span class="orderTime"></span></div>-->
    <!--</li>-->
    <!--</ul>-->
    <!--<div class="evaluateInfo">-->
    <!--<div class="proInfo" id="proInfo-content">-->

    <!--</div>-->
    <!--<div class="manyi">-->
    <!--<span>货品满意度：</span>-->
    <!--<i class="aui-iconfont aui-icon-favorfill"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill"></i>-->
    <!--<span class="manyiWaring active">*请评分</span>-->
    <!--</div>-->
    <!--<div>-->
    <!--<textarea class="problemText" oninput="checkWord(this)" onpropertychange="checkWord(this)"-->
    <!--placeholder="请谈谈您对该产品的感受"></textarea>-->
    <!--<span class="aui-pull-right">-->
    <!--<em class="sum ">0</em>/500-->
    <!--</span>-->
    <!--<div class="waring active">*请谈谈您对该货品的感受！</div>-->
    <!--</div>-->
    <!--<ul class="evualuateLilst">           -->
    <!--<li>-->
    <!--<div class="evaluateTitle">面料</div>-->
    <!--<span class="evaluteValue " tapmode onclick="checkEvaluate(this)">符合预期</span>-->
    <!--<span class="evaluteValue" tapmode onclick="checkEvaluate(this)">以次充好</span>-->
    <!--<div class="waring active">*请选择您对面料的印象！</div>-->
    <!--</li>           -->
    <!--<li>-->
    <!--<div class="evaluateTitle">色牢度</div>-->
    <!--<span class="evaluteValue" tapmode onclick="checkEvaluate(this)">正常浮色</span>-->
    <!--<span class="evaluteValue" tapmode onclick="checkEvaluate(this)">轻微掉色</span>-->
    <!--<span class="evaluteValue" tapmode onclick="checkEvaluate(this)">严重掉色</span>-->
    <!--<div class="waring active">*请选择您对色牢度的印象！</div>-->
    <!--</li>           -->
    <!--<li>-->
    <!--<div class="evaluateTitle">材质</div>-->
    <!--<span class="evaluteValue" tapmode onclick="checkEvaluate(this)">符合预期</span>-->
    <!--<span class="evaluteValue" tapmode onclick="checkEvaluate(this)">以次充好</span>-->
    <!--<div class="waring active">*请选择您对色牢度的印象！</div>-->
    <!--</li>-->
    <!--</ul>-->
    <!--</div>-->
    <!--<ul class="compare">-->
    <!--<li>-->
    <!--供应商考评:<span class="comName">Aileen纱纺有限公司 </span>-->
    <!--</li>     -->
    <!--<li class="taidu">-->
    <!--<span>服务态度: </span>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<span class="fuwuWaring active">*请评分</span>-->
    <!--</li>  -->
    <!--<li class="sudu">-->
    <!--<span>到货速度: </span>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<i class="aui-iconfont aui-icon-favorfill active"></i>-->
    <!--<span class="suduWaring active">*请评分</span>-->
    <!--</li>             -->
    <!---->
    <!--</ul>-->
</div>


<script id="orderInfo-template" type="text/x-dot-template">

    <ul class="aui-list-view">
        <li class="aui-list-view-cell">
            <div>订单号：<span class="orderNo">{{=it.order_sn}}</span></div>
            <div>下单时间：<span class="orderTime">{{=it.addtime}}</span></div>
        </li>
    </ul>
    {{ for(var g in it.goods){ }}
    <div class="evaluateInfo" goodsId="{{=it.goods[g].mallid}}">
        <div class="proInfo" id="proInfo-content">
            <img class="" src="{{=it.goods[g].thumb}}" alt="">
            <div class="proTitle">
                <div class="aui-ellipsis-2 proName">{{=it.goods[g].title}}</div>
                <div class="good-price">￥<span class="proPrice">{{=it.goods[g].amount}}</span></div>
            </div>

        </div>
        <div class="manyi ">
            <div class="manyi2 validate">
                <span>货品满意度：</span>
                <i class="aui-iconfont aui-icon-favorfill" tapmode onclick="clickStart(this)"></i>
                <i class="aui-iconfont aui-icon-favorfill" tapmode onclick="clickStart(this)"></i>
                <i class="aui-iconfont aui-icon-favorfill" tapmode onclick="clickStart(this)"></i>
                <i class="aui-iconfont aui-icon-favorfill" tapmode onclick="clickStart(this)"></i>
                <i class="aui-iconfont aui-icon-favorfill" tapmode onclick="clickStart(this)"></i>
                <span class="waring active manyiWaring">*请评分</span>
            </div>
        </div>
        <div>
            <textarea class="problemText validate" oninput="checkWord(this)" onpropertychange="checkWord(this)"
                      placeholder="请谈谈您对该产品的感受"></textarea>
            <span class="aui-pull-right">
                    <em class="sum ">0</em>/500
                </span>
            <div class="waring active">*请谈谈您对该货品的感受！</div>
        </div>
    </div>
    {{}}}

</script>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript">
    var orderId,parentOrderId;
    apiready = function () {
//        $(".contain").hide();
        getStorageAll();
        api.parseTapmode();

//        goodsId = api.pageParam.goodsId;
        orderId = api.pageParam.orderId;
        getData();
        companyName = api.pageParam.companyName;
        var header = $api.dom('header');
        var footer = $api.dom('footer');
        //$api.fixIos7Bar(header);
        // api.setStatusBarStyle({
        //       style : 'light'
        // });
    }
    //    $(document).on("click", ".manyi i,.taidu i,.sudu i", function () {
    //        $(this).parent().removeClass("validate");
    //        $(this).parent().find("i").removeClass("active")
    //        var index = $(this).index();
    //        for (var i = 0; i < index; i++) {
    //            $(this).parent().find("i").eq(i).addClass("active");
    //        }
    //        $(this).parent().find(".manyiWaring").css({"visibility": "hidden"});
    //    })
    function clickStart(obj) {
        $(obj).parent().removeClass("validate");
        $(obj).parent().find("i").removeClass("active")
        var index = $(obj).index();
        for (var i = 0; i < index; i++) {
            $(obj).parent().find("i").eq(i).addClass("active");
        }
        $(obj).parent().find(".manyiWaring").css({"visibility": "hidden"});
    }
    function checkWord(obj) {
        var len = $(obj).val().length;
        $(".sum").text(len);
        var value = $(obj).val();
        if (value != "") {
            $(obj).removeClass("validate");
            if (len >= 500) {
                $(obj).val(value.substring(0, 500));
                $(".sum").addClass("sumRed");
                api.toast({
                    msg: "字数已超过500",
                    duration: 2000
                })
            } else {
                $(".sum").removeClass("sumRed");
                $(obj).parent().find(".waring").css({"visibility": "hidden"});

            }
        } else {
            if (!$(obj).hasClass("validate")) {
                $(obj).addClass("validate");
            }
        }

    }
    function checkEvaluate(obj) {
        $(obj).parent().find("span").removeClass("active");
        $(obj).addClass("active");
        $(obj).parent().find(".waring").css({"visibility": "hidden"});
    }
    function submitEvaluate() {
        // 判断感受
        var canSumbit = true;//是否可以提交
        $(".contain").find(".validate").each(function () {
            canSumbit = false;
            $(this).parent().find(".waring").css({"visibility": "visible"});
        })

        // 判断评分
//        var manyi = $(".manyi").find("i").hasClass("active");
//        if (manyi) {
//            $(".manyi").find(".manyiWaring").css({"visibility": "hidden"});
//        } else {
//            $(".manyi").find(".manyiWaring").css({"visibility": "visible"});
//        }

//       var fuwu=$(".fuwu").find("i").hasClass("active");
//       if(fuwu){
//           $(".fuwu").find(".fuwuWaring").css({"visibility":"hidden"});
//       }else{
//           $(".fuwu").find(".fuwuWaring").css({"visibility":"visible"});
//       }

//       var sudu=$(".sudu").find("i").hasClass("active");
//       if(sudu){
//           $(".sudu").find(".suduWaring").css({"visibility":"hidden"});
//       }else{
//           $(".sudu").find(".suduWaring").css({"visibility":"visible"});
//       }
        // 判断选择的
//        var result=false;
//        $(".evualuateLilst").find("li").each(function(){
//            $(this).find("span").each(function(){
//                if($(this).hasClass("active")){
//                    result=true;//存在active表示已经选择了
//                    return false;
//                }
//            })
//            if(!result){
//                $(this).find(".waring").css({"visibility":"visible"});
//            }else{
//                $(this).find(".waring").css({"visibility":"hidden"});
//            }
//            result=false;
//        })
        //判断是否可以提交
        if (canSumbit) {
            var sumbitLen=0;//是否商品的评论上传成功，成功就修改订单状态
            $(".contain").find(".evaluateInfo").each(function () {
                goodsId=$(this).attr("goodsId");
                var commentText = $(this).find(".problemText").eq(0).val();
                var startCount = $(this).find(".manyi").eq(0).find("i.active").length;

                data = {
                    buyer: user_name,
                    seller: companyName,
                    goodsId: goodsId,
                    satisfactionDegree: startCount,
                    buyerComment: commentText,
                    orderId: orderId
                };
                url = "User/commentAdd";
                ajaxRequest(url, 'post', data, function (ret, err) {
                    if (ret.status == 1) {
//                        api.toast({
//                            msg: "评论已提交！"
//                        })
                        //评论成功后修改订单状态
                        sumbitLen++;
                        canChangeStatus=true;

                        if(sumbitLen==$(".contain").find(".evaluateInfo").length){
                            var url2="Order/orderStatusModify/userName/"+ user_name+"/orderId/"+orderId+"/status/5/type/2"
                            ajaxRequest(url2, 'post', {}, function (ret, err) {
                                if (ret.status == 1) {
                                    api.toast({
                                        msg: "评论已提交！"
                                    })
                                    updateOrderNum();
                                    setTimeout(function () {
                                        api.closeWin();
                                    }, 2000)
                                }else{
                                    api.toast({
                                        msg: '状态修改出错，请稍后重试',
                                        duration: 2000,
                                        location: 'bottom'
                                    });
                                }
                            })
                        }

                    } else {
                        canChangeStatus=false;
                        api.toast({
                            msg: '评论提交出错，请稍后重试',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                });
            })

        } else {
            api.toast({
                msg: "请完成填写！"
            })
        }

    }
    //获取商品信息
    function getData() {
        if (!user_id) {
            user_id = "";
        }
        var url = 'User/orderInfoUser';
        showLoading();
        var data = {
            orderId: orderId,
            userName: user_name,
        };

        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                var content = $api.byId('orderInfo-content');
                var tpl = $api.byId('orderInfo-template').text;
                var tempFn = doT.template(tpl);
                $api.html(content, '');
                $api.html(content, tempFn(ret.msg));
                $(".contain").show();
                var header = $api.dom('header');
                $api.fixIos7Bar(header);
                hideLoading();

                //判断是否是单击了付款按钮进来
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });


//        ajaxRequest(url, 'get', data, function (ret, err) {
//            if (ret.status == 1) {
//
//                var content = $api.byId('proInfo-content');
//                var tpl = $api.byId('proInfo-template').text;
//                var tempFn = doT.template(tpl);
//                $api.html(content, '');
//                $api.html(content, tempFn(ret.msg));
//                getOrderInfo(orderId);//商品存在，获取订单信息
//                hideLoading();
//            } else {
//                hideLoading();
//                api.toast({
//                    msg: "商品不存在，不能继续评价了",
//                    duration: 2000,
//                    location: 'middle'
//                });
//                setTimeout(function () {
//                    api.closeWin();
//                },2000)
//            }
//        });

    }
    //获取订单的信息，显示订单表和时间
    function getOrderInfo(orderId) {
        showLoading();
        var data = {
            orderId: orderId,
            userName: user_name,
        };
        var url = 'User/orderInfoUser';
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                $(".orderNo").text(ret.msg.order_sn);
                $(".orderTime").text(ret.msg.addtime);
                var header = $api.dom('header');
                $api.fixIos7Bar(header);
                hideLoading();
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
                hideLoading();

            }
        });
    }
</script>
</html>
